package com.lavender.circle_dependency.setter_dependency_prototype;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 3：setter注入（Prototype模式）造成循环依赖的方式
 * # @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
 * 不会报错循环依赖。
 * # @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 * 会报错循环依赖。（需要手动getBean或者在一个单例Bean内@Autowired才会触发）
 *
 * 补充知识点：
 * 对Bean设置prototype类型时，需要设置proxyMode，否则prototype设置无效。
 * @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)：多例有效
 * @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)：多例无效
 *
 * </p>
 *
 * @author: zhu.chen
 * @date: 2020/12/24
 * @version: v1.0.0
 */
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Component
public class SetterPrototypeA {

    @Autowired
    private SetterPrototypeB setterPrototypeB;

}
